<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

    <head>
        <meta charset="utf-8">
            <title>淘天机站群系统管理后台</title>
            <!-- include header_meta -->
    </head>

    <body>
        <!-- include header -->
        <div class="cp-wrap {if $jnarrow}jnarrow{/if}">
            <div class="crumb"></div>
            <div class="cp-table-top cl">
                <div class="fl">
                    <input type="submit" class="btn" value="添加站点" onclick="window.location.href = '?m=yuming&a=add'">
                    <input type="submit" class="btn" value="导入站点" onclick="window.location.href = '?m=import&a=index'">
                        <input type="submit" class="btn" value="导入百度推送" onclick="window.location.href = '?m=importbaidu&a=index'">
                </div>
                <div class="fr">
                    <form action="?m=yuming&a=index" method="post">
                        <input name="yuming_name" value="{$name}" type="text" placeholder="请输入您要搜索的站点">
                            <input type="submit" value="搜索" class="btn" />
                    </form>
                </div>
            </div>
            <div class="cp-table">
                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tbody>
                        <tr>
                            <th align="left">ID</th>
                            <th align="left">域名</th>
                            <th align="left">网站名称</th>
                            <th align="left">手机版</th>
                            <!--<th align="left">手机版域名</th>-->
                            <th align="left">网站风格</th>
                            <th align="left">加入自动采集任务</th>
                            <th align="left">开启寄生虫</th>
                            <th align="left">可登录后台</th>
                            <th align="center">操作</th>
                        </tr>
                        <!-- foreach $list -->
                        <tr>
                            <td align="left"><input type="checkbox" name="id" class="table-main" value="{$id}">&nbsp;&nbsp;{$id}</td></td>
                            <td align="left" id="yuming_{$id}"><a href="http://{$name}" target="_blank" class="unpjax">{$name}</a></td>
                            <td align="left">{$sitename}</td>
                            <td align="left">
                                <div class="switch turnbg_{$mobileSwitch}" data="{$mobileSwitch}" onclick="changeSwitch('{$id}', this)" title="开启后需将手机域名同时解析和绑定到程序所在目录"></div>
                            </td>
                            <!--<td align="left" class="wapurl" id="{$name}" sh="{$mobileSwitch}"></td>-->
                            <td align="left">{$template}</td>
                            <td align="left" class="cj" id="{$autoCatch}" rel="{$id}" title="开启此开关后将加自动采集数据，请确保栏目、关建词库和配置等一切都已设定好再开启。">
                                <div class='switch turnbg_{$autoCatch}' data="{$autoCatch}" onclick='changeCaiji("{$id}",this)'></div>
                            </td>
                            <td align="left" class="jsc" id="{$autojsc}" rel="{$id}" title="开启此开关后将加自动寄生虫任务">
                                <div class='switch turnbg_{$autojsc}' data="{$autojsc}" onclick='changeJsc("{$id}",this)'></div>
                            </td>
                            <td align="left">
                                <div class="switch turnbg_0 isadmin" ref="{$id}"  title="只允许有一个站点可登录后台"></div>
                            </td>
                            <td align="center">
                                <a href="?m=yuming&a=edit&id={$id}" class="action_button fa fa-edit fa-fw" title="修改"></a>
                                <a href="javascript:void(0);" data-href="?m=yuming&a=del&id={$id}" class="deleteAction action_button fa fa-trash-o fa-fw" title="删除"></a>
                            </td>
                        </tr>
                        <!-- /foreach -->
                    </tbody>
                </table>
            </div>
            <div id="msg" style="padding-left:20px;color:red;"></div>
            <div class="cp-table-top">
                    <label>
                            <input type="checkbox" id="all" onclick="check_all()" />全选</label>&nbsp;
                    <a class="btn" id="change_all" href="javascript:void(0);">批量采集任务</a>
                    <a class="btn" id="close_all" href="javascript:void(0);">取消采集任务</a>
                    <a class="btn" id="del_all" href="javascript:void(0);">批量删除站点(谨慎操作)</a>
                    <a class="btn" id="jsc_all" href="javascript:void(0);">加入寄生虫</a>
                    <a class="btn" id="del_jsc_all" href="javascript:void(0);">取消寄生虫</a>
                    
            </div>
            <!-- if empty($list) -->
            <div class="noresult">暂时没有可显示数据</div>
            <!-- /if -->
            <div class="cp-pages">
                {$page}
            </div>
        </div>
        <!-- include footer -->
        <script type="text/javascript" src="__APPROOT__/js/layer/layer.js"></script>
        <script type="text/javascript">
            $(function(){
               $('.deleteAction').click(function(){
                  var i = $(this);
                  var tt = layer.confirm('确认要删除吗？', {
                    btn: ['是的','取消'] //按钮
                  }, function(){
                      layer.close(tt);
                      layer.prompt({title: '请输入管理员密码，并确认', formType: 1}, function(pass, index){
                        layer.close(index);
                        var href = i.attr('data-href');
                        $.post(href,{pass:pass},function(res){
                            if(res.suc==1) {
                                cpAlert('删除成功');
                                window.location.reload();
                            }else {
                                layer.msg(res.message);
                                return;
                            }
                         },'json');
                      });                  
                  }, function(){
                    layer.close(tt);
                  });
               });
               
               $('#del_all').click(function(){
                    var checkID = [];
                    $("input[name='id']:checked").each(function(i){
                        checkID[i] =$(this).val(); 
                    });
                    if(checkID.length==0) {
                        $("#msg").text("请最少选择一项！");
                        return false;
                    }else {
                        $("#msg").text("");
                    }
                    var tt = layer.confirm('确认要删除吗,这会导致已有的数据删除后不可找回？', {
                      btn: ['是的','取消'] //按钮
                    }, function(){
                        layer.close(tt);
                        layer.prompt({title: '请输入管理员密码，并确认', formType: 1}, function(pass, index){
                          layer.close(index);
                          $.post("?m=yuming&a=del",{pass:pass,id:checkID},function(res){
                              if(res.suc==1) {
                                  cpAlert('删除成功');
                                  window.location.reload();
                              }else {
                                  layer.msg(res.message);
                                  return;
                              }
                           },'json');
                        });                  
                    }, function(){
                      layer.close(tt);
                    });
               });
               
               
            });
            function changeSwitch(yuming_id, obj) {
                var tt = $(obj).attr("data");
                if (tt == 1) {
                    $(obj).removeClass("turnbg_1");
                    $(obj).addClass("turnbg_0");
                    $(obj).attr("data", 0);
                } else {
                    $(obj).removeClass("turnbg_0");
                    $(obj).addClass("turnbg_1");
                    $(obj).attr("data", 1);
                }
                var ts = $(obj).attr("data");
                $.ajax({
                    'url': "?m=yuming&a=switchval",
                    'type': 'post',
                    'dataType': 'json',
                    'data': {'yuming_id': yuming_id, 'data': ts},
                    success: function (data) {
                        cpAlert(data.msg);
                        var wobj = $(obj).closest("tr").find(".wapurl");
                        if (wobj.attr('sh') == 1) {
                            wobj.attr('sh', 0)
                        } else {
                            wobj.attr('sh', 1)
                        }
                        loadWapUrl();
                    }
                })
            }

            function changeCaiji(yuming_id, obj) {
                var tt = $(obj).attr("data");
                if (tt == 1) {
                    $(obj).removeClass("turnbg_1");
                    $(obj).addClass("turnbg_0");
                    $(obj).attr("data", 0);
                } else {
                    $(obj).removeClass("turnbg_0");
                    $(obj).addClass("turnbg_1");
                    $(obj).attr("data", 1);
                }
                var ts = $(obj).attr("data");
                $.ajax({
                    'url': "?m=yuming&a=switchcaiji",
                    'type': 'post',
                    'dataType': 'json',
                    'data': {'yuming_id': yuming_id, 'data': ts},
                    success: function (data) {
                        cpAlert(data.msg);
                    }
                })
            }
            
            function changeJsc(yuming_id, obj) {
                var tt = $(obj).attr("data");
                if (tt == 1) {
                    $(obj).removeClass("turnbg_1");
                    $(obj).addClass("turnbg_0");
                    $(obj).attr("data", 0);
                } else {
                    $(obj).removeClass("turnbg_0");
                    $(obj).addClass("turnbg_1");
                    $(obj).attr("data", 1);
                }
                var ts = $(obj).attr("data");
                $.ajax({
                    'url': "?m=yuming&a=switchjsc",
                    'type': 'post',
                    'dataType': 'json',
                    'data': {'yuming_id': yuming_id, 'data': ts},
                    success: function (data) {
                        cpAlert(data.msg);
                    }
                })
            }
  
            
        </script>

        <script>
            function loadWapUrl() {
                $('.wapurl').each(function () {
                    var name = $(this).attr("id");
                    var sh = $(this).attr("sh");
                    if (sh == 1) {
                        if (name.indexOf("www") == 0) {
                            var reg = new RegExp("www", "g");
                            var myhtml = "m" + name.replace(reg, "");
                            $(this).html(myhtml);
                        } else {
                            var myhtml = "m." + name;
                            $(this).html(myhtml);
                        }
                    } else {
                        $(this).html("");
                    }
                })
            }
            loadWapUrl();
        </script>
        <script type="text/javascript">
            $(function(){
                $('#change_all').click(function(){
                    submit_caiji(0);
                });
                $('#close_all').click(function(){
                    submit_caiji(1);
                });
                
                $('#jsc_all').click(function(){
                    submit_jsc(0);
                });
                $('#del_jsc_all').click(function(){
                    submit_jsc(1);
                });
            });
                
            function submit_caiji(close) {
                var checkID = [];
                $("input[name='id']:checked").each(function(i){
                    checkID[i] =$(this).val(); 
                });
                if(checkID.length==0) {
                    $("#msg").text("请最少选择一项！");
                    return false;
                }else {
                    $("#msg").text("");
                }
                var loading = layer.load(1, {
                    shade: [0.3,'#000'] //透明度的背景
               });
                $.post('?m=yuming&a=tocaiji',{'ids':checkID,close:close},function(res){
                    layer.close(loading);
                    if(res.status==1) {
                        window.location.reload();
                    }else {
                        layer.alert(res.msg);
                        return false;
                    }
                });
            }
            
            function submit_jsc(close) {
                var checkID = [];
                $("input[name='id']:checked").each(function(i){
                    checkID[i] =$(this).val(); 
                });
                if(checkID.length==0) {
                    $("#msg").text("请最少选择一项！");
                    return false;
                }else {
                    $("#msg").text("");
                }
                var loading = layer.load(1, {
                    shade: [0.3,'#000'] //透明度的背景
               });
                $.post('?m=yuming&a=tojsc',{'ids':checkID,close:close},function(res){
                    layer.close(loading);
                    if(res.status==1) {
                        window.location.reload();
                    }else {
                        layer.alert(res.msg);
                        return false;
                    }
                });
            }
            
                
            function check_all() {
                var ids = document.getElementById("all");
                if (ids.checked) {
                        $(".table-main").each(function() {
                                $(this).prop("checked", true);
                        })
                } else {
                        $(".table-main").each(function() {
                                $(this).prop("checked", false);
                        })
                }
            }
	</script>
    </body>

</html>